/**
 * 
 */
package com.ruyipu.forum.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ruyipu.forum.R;
import com.ruyipu.forum.interfaces.IItem;
import com.ruyipu.forum.item.Discussion;

/**
 * @author donald
 * 
 */
public class DiscussionAdapter extends BaseAdapter {
	
	public DiscussionAdapter(Context context, List<IItem> dataList) {
		super(context, dataList);
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getView(int, android.view.View,
	 * android.view.ViewGroup)
	 */
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout layout = (LinearLayout) getView(convertView, R.layout.discussion_item);
		Discussion discussion = (Discussion) dataList.get(position);
		TextView tvName = (TextView) layout.findViewById(R.id.tvDiscussionName);
		TextView tvDiscussionCommentCount = (TextView) layout
				.findViewById(R.id.tvDiscussionCommentCount);
		TextView tvCreator = (TextView) layout.findViewById(R.id.tvCreator);
		TextView tvDateInserted = (TextView) layout
				.findViewById(R.id.tvDateInserted);
		final ImageView ivBookmark = (ImageView) layout
				.findViewById(R.id.ivBookmark);
		String name = discussion.getName();
		if(name.length() > 20) {
			name = name.substring(0, 15) + "...";
		}
		tvName.setText(name);
		if(discussion.isAnnouncement()) {
			tvName.setTextColor(R.color.second);
		}
		tvDiscussionCommentCount.setText(String.format(
				context.getString(R.string.comment_count),
				discussion.getCountComment()));
		tvCreator.setText(String.format(context.getString(R.string.started_by),
				discussion.getFirstName()));
		tvDateInserted.setText(discussion.getDate());
		if (discussion.getBookmarked()) {
			ivBookmark.setImageResource(R.drawable.star_fav);
		}
		ivBookmark.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				
			}
		});
		return layout;
	}

}
